/**
 * User: alesj
 * Date: 2005.6.1
 * Time: 15:33:28
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.alesj.newsfeed.data;

import java.util.Set;
import java.io.Serializable;

import org.springframework.beans.factory.BeanFactory;

import com.generalynx.common.data.ADEData;
import com.generalynx.common.data.dao.IEntityDAO;
import com.generalynx.common.resources.Resources;

public class GroupEntry extends ADEData implements Serializable {

    private static final long serialVersionUID = 1L;

    private int id;
    private String name;
    private String description;
    private Group group;
    private Set contacts;

    public String getAddLabel() {
        return Resources.getString(Resources.FILTER);
    }

    protected String getNameLabel() {
        return getName();
    }

    protected String getInfo() {
        return String.valueOf(getContacts().size());
    }

    protected String getSelectAction() {
        return "entryContactSelect";
    }

    public String getLabel() {
        return getName() + (getGroup() != null ? " [" + getGroup().getName() + "]" : "");
    }

    public void afterCreate() {
        setGroup(new Group());
    }

    public void beforeBind() {
        afterCreate();
    }

    public void beforeSaveOrUpdate(BeanFactory beanFactory) {
        IEntityDAO entityDAO = (IEntityDAO)beanFactory.getBean(IEntityDAO.entityDAO);
        if (entityExists(getGroup())) {
            setGroup((Group)entityDAO.loadEntity(Group.class, getGroup().getId()));
        } else {
            setGroup(null);
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Group getGroup() {
        return group;
    }

    public void setGroup(Group group) {
        this.group = group;
    }

    public Set getContacts() {
        return contacts;
    }

    public void setContacts(Set contacts) {
        this.contacts = contacts;
    }

}
